package com.operator.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.MsgNotice;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：金泽云 手机app
 * 类描述：推送通知 适配器
 * 创建人：张飞祥
 * 创建时间：2018/7/4 9:56
 * 修改人：张飞祥
 * 修改时间：2018/7/4 9:56
 * 修改备注：
 */
public class MsgNoticeAdapter extends BaseRecyclerViewAdapter {


    //上下文
    private Context mContext;
    //数据集合
    private List<MsgNotice> mList;

    public MsgNoticeAdapter(Context mContext, List<MsgNotice> mList) {
        super(mContext, mList);
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_msg_notice;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof MsgNoticeViewHolder) {

            //TODO 获取充值记录 viewHolder
            final MsgNoticeViewHolder holder = (MsgNoticeViewHolder) viewHolder;
            //TODO  将数据保存在itemView的Tag中，以便点击时进行获取
            holder.itemView.setTag(position);
            //TODO  获取数据源 第 i 个 实体数据
            MsgNotice msgNotice = mList.get(position);

            /**
             * 设置数据源
             */
            //推送时间
            holder.tvItemMsgTime.setText(msgNotice.getCreateTime());
            //推送内容
            holder.tvItemMsgContent.setText(msgNotice.getMsg());
        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new MsgNoticeViewHolder(view);
    }

    /**
     * ViewHolder
     */
    public class MsgNoticeViewHolder extends RecyclerView.ViewHolder {

        //时间
        @Bind(R.id.tv_item_msg_time)
        TextView tvItemMsgTime;
        //内容
        @Bind(R.id.tv_item_msg_content)
        TextView tvItemMsgContent;

        public MsgNoticeViewHolder(View itemView) {
            super(itemView);

            //初始化控件
            ButterKnife.bind(this,itemView);
            //屏幕适配
            AutoUtils.auto(itemView);
        }
    }
}
